package com.baichuan.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: kun
 * @Date: 2020/04/25 10:04
 * @Description: List数据泛型转换拷贝
 */
public class CopyUtil {
    public static<T,F> List<F> convertList(List<T> sourceList,Class<F> target) {
        if (StringUtils.isNotEmpty(sourceList)) {
            List targetList = new ArrayList();
            for (T t : sourceList) {
                try {
                    F f = target.newInstance();
                    BeanUtils.copyProperties(t, f);
                    targetList.add(f);
                } catch (Exception e) {
                }
            }
            return targetList;
        }
        return null;
    }

}
